/**
 * 
 */
package com.auth.action;

import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.auth.model.Role;
import com.auth.service.RoleService;
import com.auth.service.RoleServiceImpl;
import com.util.MenuUtil;


public class RoleAction extends AbstractAction
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	private RoleService service;
	
	public RoleAction()
	{
		logger = Logger.getLogger(this.getClass());
		service = new RoleServiceImpl();
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<Role> roles;
	private Role       role;
	private String     type;
	private List<MenuUtil.Menu> menus;
	
	public String list()
	{
		logger.debug("list role");
		roles = service.getRoles();
		return SUCCESS;
	}
	
	public String show()
	{
		logger.debug("show role");
		if (role.getId() == -1)
		{
			role.setValue("");
			type = "insert";
		}
		else
		{
			role = service.getRole(role.getId());
			type = "update";
		}
		menus = MenuUtil.getInstance().getMenu();
		return SUCCESS;
	}
	
	public String save()
	{
		logger.debug("save role");
		service.saveRole(operator, type, role);
		return SUCCESS;
	}

	/**
	 * @return the roles
	 */
	public List<Role> getRoles() {
		return roles;
	}

	/**
	 * @param roles the roles to set
	 */
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	/**
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * @param role the role to set
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the menus
	 */
	public List<MenuUtil.Menu> getMenus() {
		return menus;
	}

	/**
	 * @param menus the menus to set
	 */
	public void setMenus(List<MenuUtil.Menu> menus) {
		this.menus = menus;
	}
	
	public int getMenuCount()
	{
		return MenuUtil.getInstance().getMenuCount();
	}
}
